clear 
capture log close
log using bias_bymajor_graphs.txt, text replace

/**************************************
/* Analysis of bias by Major */
Author: Andrew Foote
Date:  
Update: 1/4/2024

*************************************/


include .\config.do 

set more off 
set scheme s1mono 
version 16 

import delimited "$datadir\20230920\bias_scatter_cip_byyear_2023-09-08.csv", clear 

gen str40 cip_lab = ""
replace cip_lab = "Agriculture" if cip==1
replace cip_lab = "Architecture" if cip==4
replace cip_lab = "Area, ethnic, cultural, gender studies" if cip==5
replace cip_lab = "Communication and journalism" if cip==9
replace cip_lab = "Computer and information sciences" if cip==11
replace cip_lab = "Educaton" if cip==13
replace cip_lab = "Engineering" if cip==14
replace cip_lab = "Engineering technology" if cip==15
replace cip_lab = "Foreign language, literatures, and linguistics" if cip==16
replace cip_lab = "Family and consumer sciences" if cip==19
replace cip_lab = "Legal professions" if cip==22
replace cip_lab = "English" if cip==23
replace cip_lab = "Liberal arts and sciences" if cip==24
replace cip_lab = "Biology" if cip==26
replace cip_lab = "Mathematics and statistics" if cip==27
replace cip_lab = "Parks, recreation, leisure, fitness" if cip==31
replace cip_lab = "Philosophy and religious studies" if cip==38
replace cip_lab = "Physical sciences" if cip==40
replace cip_lab = "Security and protective services" if cip==43
replace cip_lab = "Public administration and social service" if cip==44
replace cip_lab = "Social sciences" if cip==45
replace cip_lab = "Visual and performing arts" if cip==50
replace cip_lab = "Health professions" if cip==51
replace cip_lab = "Business, management, marketing" if cip==52
replace cip_lab = "History" if cip==54




gen bias = beta_out - beta_in 

bysort cip: egen n_out_cip = total(n_out)

table cip year_post [aw=n_out] , c(mean bias) col row 

table cip, c(sum n_out) col row


table cip year_post [aw=n_missing] , c(mean beta_missing) col row 

table cip year_post if state == 48 | state ==8 [aw=n_out] , c(mean bias) col row 

graph hbar (mean) bias (mean) beta_missing [aw = n_out] if (n_out_cip > 2000), over(cip_lab , sort((mean) bias) label(labsize(*.5)) ) legend(label(1 "Bias") label (2 "Difference in No Earnings"))
graph export "$graphdir/bias_by_major.png", replace 

preserve
keep if year_post == 1 | year_post == 5 | year_post == 10

graph hbar (mean) bias [aw = n_out] if (n_out_cip > 2000), over(year_post, label(labsize(*.5))) over(cip_lab , sort((mean) bias) label(labsize(*.5)))  legend(label(1 "Bias") )
graph export "$graphdir/bias_by_major_time.png", replace 
restore

rename beta_missing missing_diff 



log close



